package com.szrt.oa.employee.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.szrt.oa.base.controller.BaseController;
import com.szrt.oa.department.dao.DepartmentDao;
import com.szrt.oa.department.entity.DepartmentEntity;
import com.szrt.oa.department.service.DepartmentService;
import com.szrt.oa.employee.entity.EmployeeEntity;
import com.szrt.oa.employee.service.EmployeeService;


@Controller
@RequestMapping("/employee")
public class EmployeeController extends BaseController<EmployeeEntity> {
	
	@Autowired
	private EmployeeService service;
	
	@Autowired
	private EmployeeEntity entity;
	

	
	//http://localhost:8090/super-base-ssm/employee/myquery?username=lh
	//http://localhost:8090/super-base-ssm/employee/myquery
	@RequestMapping("/myquery")
	@ResponseBody
	public Map<String, Object> myquery(EmployeeEntity entity) {
		
		
		Map<String, Object> insert = service.queryById(entity);
		return insert;
	}
	
	
	
	
	//分页2 
	//http://localhost:8090/super-base-ssm/employee/findPage2?pageIndex=1&pageSize=2
	//http://localhost:8090/super-base-ssm/employee/findPage2.do
	@RequestMapping("/findPage2")
	@ResponseBody
	public Map<String, Object> findPage2(String pageIndex,String pageSize) {
		
		Map<String, Object> queryByPage = service.myfindpage(Integer.parseInt(pageIndex), Integer.parseInt(pageSize));
		return queryByPage;
	}
	
	
	//删除
	//http://localhost:8090/super-base-ssm/employee/mydel.do?id=1
	//http://localhost:8090/super-base-ssm/employee/mydel.do
	@RequestMapping("/mydel")
	@ResponseBody
	public Map<String, Object>  mydel(String idStr) {
		
		
		String[] split = idStr.split(",");
		Map<String, Object>  map=new HashMap<String,Object>();
		int counter=0;
		for (String s : split) {
			entity.setId(Integer.parseInt(s));
			Map<String, Object>  mydelete = service.deleteByid(entity);
			String code = (String)mydelete.get("code");
			if("200".equals(code)){
				counter++;
			}
		}
		//
		if(counter>=1){
			map.put("code", 200);
			map.put("mycounter", counter);
		}else{
			map.put("code", 999);
		}
		return map;
	}
	
	//修改
	//http://localhost:8090/super-base-ssm/employee/myupdate.do?username=lh&id=1
	@RequestMapping("/myupdate")
	@ResponseBody
	public Map<String, Object>  myupdate(EmployeeEntity entity) {
		
		Map<String, Object>  myupdate = service.update(entity);
		return myupdate;
	}
	
	//http://localhost:8090/super-base-ssm/employee/myinsert.do?username=lh乱码
	//http://localhost:8090/super-base-ssm/employee/myinsert.do
	@RequestMapping("/myinsert")
	@ResponseBody
	public Map<String, Object>  myinsert(EmployeeEntity entity) {
		
		Map<String, Object>  myinsert = service.insert(entity);
		return myinsert;
	}
	
	
	
}
